/**
 * 
 */
package com.haizhi.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.haizhi.bean.TbComment;
import com.haizhi.bean.TbProduct;
import com.haizhi.bean.TbUser;
import com.haizhi.bean.TbUserCollection;
import com.haizhi.dao.UserCollectionDao;
import com.haizhi.service.UserCollectionService;

/**
 * @author jiangjintai
 *
 */
@Service("userDataService")
public class UserCollectionServiceImpl extends BaseServiceImpl<TbUserCollection, Integer>
		implements UserCollectionService {
	@Autowired
	UserCollectionDao userCollectionDao;
	
	/* （非 Javadoc）
	 * @see com.haizhi.service.impl.BaseServiceImpl#getDao()
	 */
	@Override
	protected JpaRepository<TbUserCollection, Integer> getDao() {
		return userCollectionDao;
	}

	/* （非 Javadoc）
	 * @see com.haizhi.service.UserCollectionService#saveAndUpdateTbProduct(com.haizhi.bean.TbUserCollection)
	 */
	@Override
	public void saveAndUpdateTbProduct(TbUserCollection tbUserCollection) {
		// 
		this.save(tbUserCollection);
		tbUserCollection.getTbProduct().setProductStartNum(tbUserCollection.getTbProduct().getProductStartNum()+1);
		this.save(tbUserCollection);
		
	}

	/* （非 Javadoc）
	 * @see com.haizhi.service.UserCollectionService#deleteAndUpdateTbProduct(com.haizhi.bean.TbProduct, com.haizhi.bean.TbUser)
	 */
	@Override
	public void deleteAndUpdateTbProduct(TbProduct tbProduct, TbUser tbUser) {
		// 
		TbUserCollection tbUserCollection = this.userCollectionDao.findByTbProductAndTbUser(tbProduct,tbUser);
		tbProduct.getTbProduct().setProductStartNum(tbProduct.getProductStartNum()-1);
		this.delete(tbUserCollection);
	}

	/* （非 Javadoc）
	 * @see com.haizhi.service.UserCollectionService#findByTbUserAndTbProduct(com.haizhi.bean.TbUser, com.haizhi.bean.TbProduct)
	 */
	@Override
	public TbUserCollection findByTbUserAndTbProduct(TbUser tbUser,
			TbProduct tbProduct) {
		// 
		return this.userCollectionDao.findByTbUserAndTbProduct(tbUser,tbProduct);
	}

	/* （非 Javadoc）
	 * @see com.haizhi.service.UserCollectionService#findByTbUser(com.haizhi.bean.TbUser, org.springframework.data.domain.Pageable)
	 */
	@Override
	public Page<TbUserCollection> findByTbUser(TbUser tbUser, Pageable pageAble) {
		// 
		return this.userCollectionDao.findByTbUser(tbUser,pageAble);
	}

	

}
